inspector: Add a button for rtl flipping
authorMatthias Clasen <mclasen@redhat.com>
Sat, 10 May 2014 14:40:55 +0000 (10:40 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 11 May 2014 02:04:34 +0000 (22:04 -0400)
Nice to have a quick way of testing this everywhere.

The implementation is not quite perfect: due to the way text
direction works in GTK+, widgets that appear in the inspector
window while we are flipped will inherit the flipped direction
instead of the fixed direction of the inspector window.

modules/inspector/window.c
modules/inspector/window.ui

index 479c4e580298c220770170cbe624780e02fd148d..37363ef8129f2484f00910cc8332fe41fc0a3f93 100644 (file)
@@ -50,6 +50,40 @@ on_graphic_updates_toggled (GtkToggleButton    *button,
   gdk_window_set_debug_updates (gtk_toggle_button_get_active (button));
 }
 
+static void
+fix_direction_recurse (GtkWidget *widget, gpointer data)
+{
+  GtkTextDirection dir = GPOINTER_TO_INT (data);
+
+  g_object_ref (widget);
+
+  gtk_widget_set_direction (widget, dir);
+  if (GTK_IS_CONTAINER (widget))
+    gtk_container_forall (GTK_CONTAINER (widget), fix_direction_recurse, data);
+
+  g_object_unref (widget);
+}
+
+static GtkTextDirection initial_direction;
+
+static void
+fix_direction (GtkInspectorWindow *iw)
+{
+  fix_direction_recurse (GTK_WIDGET (iw), GINT_TO_POINTER (initial_direction));
+}
+
+static void
+on_flip (GtkButton          *button,
+         GtkInspectorWindow *iw)
+{
+  fix_direction (iw);
+
+  if (gtk_widget_get_default_direction () == GTK_TEXT_DIR_LTR)
+    gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
+  else
+    gtk_widget_set_default_direction (GTK_TEXT_DIR_LTR);
+}
+
 static gboolean
 on_widget_tree_button_press (GtkInspectorWidgetTree *wt,
                              GdkEventButton         *event,
@@ -126,6 +160,8 @@ gtk_inspector_window_init (GtkInspectorWindow *iw)
       g_signal_connect (G_OBJECT (iw->widget_tree), "button-press-event",
                         G_CALLBACK (on_widget_tree_button_press), iw);
     }
+
+  initial_direction = gtk_widget_get_default_direction ();
 }
 
 static void
@@ -182,6 +218,7 @@ gtk_inspector_window_class_init (GtkInspectorWindowClass *klass)
 
   gtk_widget_class_bind_template_callback (widget_class, on_inspect);
   gtk_widget_class_bind_template_callback (widget_class, on_graphic_updates_toggled);
+  gtk_widget_class_bind_template_callback (widget_class, on_flip);
   gtk_widget_class_bind_template_callback (widget_class, on_widget_tree_selection_changed);
   gtk_widget_class_bind_template_callback (widget_class, on_send_widget_to_shell_activate);
 }
index e6f643b908998ced0ed8ba5cd9ea8f3b4d613101..66d75153ef99ced4fd8201e17017afe204ffa733 100644 (file)
@@ -1,13 +1,18 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface domain="gtk30">
+  <object class="GtkImage" id="inspect_image">
+    <property name="visible">True</property>
+    <property name="icon-name">edit-find</property>
+    <property name="icon-size">4</property>
+  </object>
   <object class="GtkImage" id="update_image">
     <property name="visible">True</property>
     <property name="icon-name">view-refresh</property>
     <property name="icon-size">4</property>
   </object>
-  <object class="GtkImage" id="inspect_image">
+  <object class="GtkImage" id="flip_image">
     <property name="visible">True</property>
-    <property name="icon-name">edit-find</property>
+    <property name="icon-name">object-flip-horizontal</property>
     <property name="icon-size">4</property>
   </object>
   <object class="GtkMenu" id="widget_popup">
                 <signal name="toggled" handler="on_graphic_updates_toggled"/>
               </object>
             </child>
+            <child>
+              <object class="GtkButton">
+                <property name="visible">True</property>
+                <property name="image">flip_image</property>
+                <property name="tooltip-text" translatable="yes">Change Text Direction</property>
+                <signal name="clicked" handler="on_flip"/>
+              </object>
+            </child>
           </object>
           <packing>
             <property name="pack-type">start</property>